function Rating(divId,data){
	//this.body=$(divId);
	
	this.body=document.getElementById(divId);
	this.title=data;
	this.rating=1;
	this.updateUI();
}
Rating.prototype={
	updateUI:function(delta){
		if (!delta){ 
			delta=0; }
		if (delta>0){ this.rating++;
		}else if (delta<0){
			this.rating--;
		}
		var inner="<table border='0'><tr><td width='42'>"
		+"<span class='title'>"+this.title+"</span></td>"
		+"<td>";
		for (var i=0;i<this.rating;i++){
			inner+="<img src='images/star.png'/>"
		}
		inner+="</td></tr><td>"
		+"<img src='images/up.png' id='plus_"+this.title+"'/>"
		+"<img src='images/down.png' id='minus_"+this.title+"'/>"
		+"</td><td>"
		+"<div id='message_"+this.name+"' class='message'></div>"
		+"</td></tr></table>";
		this.body.innerHTML=inner;
		var rating=this;
		this.plusButton=document.getElementById("plus_"+this.title);
		this.minusButton=document.getElementById("minus_"+this.title);
		this.body.onclick=function(event){
			var e=(event) ? event : window.event;
			var target=(e.target) ?
			e.target : e.srcElement;
			if (target.id==rating.plusButton.id
				&& rating.rating<5){
				rating.updateUI(1);
			}else if (target.id==rating.minusButton.id
				&& rating.rating>0){
				rating.updateUI(-1);
			}
		}
		this.tellServer();
	},

	tellServer:function(){
	if (window.XMLHttpRequest){
		this.request=new XMLHttpRequest();
		} else if (window.ActiveXObject){
			this.request=new
		ActiveXObject("Microsoft.XMLHTTP");
	}
	if (!this.request){
		this.showMessage("no Ajax support");
	}
	try{
		var rating=this;
		var params="name="
		+encodeURI(this.name)
		+"&rating="
		+encodeURI(this.rating);
		this.request.onreadystatechange
		=function(){rating.onReadyState();};
		this.request.open(
			"POST","updateRating.php",true
		);
		this.request.setRequestHeader(
			'Content-Type',
			'application/x-www-form-urlencoded'
		);
		this.request.setRequestHeader(
			"Content-Length",
			params.length
		);
		this.request.send(params);
			}
	catch (err){
		this.onAjaxError(err.msg);
		}
	},
	onReadyState:function(){
		var req=this.request;
		var ready=req.readyState;
		if (ready==4){
			var httpStatus=req.status;
			if (httpStatus==200 || httpStatus==0){
				this.onAjaxLoad.call(this);
			}else{
				this.onAjaxError.call(this,"HTTP code "+httpStatus);
			}
		}
	},
	onAjaxLoad:function(){
		this.showMessage("server OK "+this.request.responseText);
	},
	onAjaxError:function(msg){
		this.showMessage("server error"+( (msg) ? " - "+msg: ""));
	},
	showMessage:function(str){
		document.getElementById("message_"+this.name).innerHTML=str;
	}
};